package query.truncate

import ast.expr.SqlIdentifierExpr
import ast.statement.truncate.SqlTruncate
import expr.DB
import expr.TableSchema
import query.ReviseQuery
import util.toSqlString
import java.sql.Connection

class Truncate(
    var db: DB = DB.MYSQL,
    override var conn: Connection? = null,
    override var isTransaction: Boolean = false
) : ReviseQuery() {
    constructor(db: DB) : this(db, null, false)

    private var sqlTruncate = SqlTruncate()

    infix fun truncate(table: String): Truncate {
        sqlTruncate.table = SqlIdentifierExpr(table)
        return this
    }

    infix fun <T : TableSchema> truncate(table: T): Truncate {
        return truncate(table.tableName)
    }

    override fun sql() = toSqlString(sqlTruncate, db)
}